package cn.wolfcode.cms.service.impl;

import cn.wolfcode.cms.domain.Present;
import cn.wolfcode.cms.mapper.PresentMapper;
import cn.wolfcode.cms.query.QueryObject;
import cn.wolfcode.cms.service.IPresentService;
import cn.wolfcode.cms.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PresentServiceImpl implements IPresentService {
    @Autowired
    private PresentMapper presentMapper;

    public void save(Present entity) {
        presentMapper.insert(entity);

    }

    public void update(Present entity) {
        presentMapper.updateByPrimaryKey(entity);
    }

    public void delete(Long id) {
        presentMapper.deleteByPrimaryKey(id);
    }

    public Present get(Long id) {
        return presentMapper.selectByPrimaryKey(id);
    }

    public List<Present> list() {
        return presentMapper.selectAll();
    }

    public Object query(QueryObject qo) {
        //查总数
        int total = presentMapper.queryForCount(qo);
        if(total == 0){
            return new PageResult();
        }
        //查数据
        List<Present> rows = presentMapper.queryForList(qo);
        return new PageResult(total, rows);
    }

    public void updateTotalNum(Long preid, Integer prenum) {
        presentMapper.updateTotalNum(preid,prenum);
    }


}
